/* 
 * BasalBodyTemperature.java v0.0.8 2011-07-05 19:01
 * : `Tab image` & `Launch image` testing (now), it was not a complete success.
 * : `@/res/drawable/icon.png` (ProfileImage@BBTProfileTab)
 * : `@/res/drawable-hdpi/icon.png` (Launch Image)
 * : `@/res/drawable-ldpi/icon.png` (Launch Image)
 * : `@/res/drawable-mdpi/icon.png` (Launch Image)
 */

package tw.BBT.BasalBodyTemperature;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.SurfaceView;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import tw.BBT.BasalBodyTemperature.Listeners.TabWidget.*;
import tw.BBT.BasalBodyTemperature.Listeners.TabPageContents.Page_Main.*;
import tw.BBT.BasalBodyTemperature.Listeners.TabPageContents.Page_Profile.*;
import tw.BBT.BasalBodyTemperature.Components.Common.*;
import tw.BBT.BasalBodyTemperature.Components.DataStructs.TemperatureHistoryStatue;

public class BasalBodyTemperature extends Activity {

	// Definition things
	// public Spinner SenserItems ;
	// public TextView SysMessage, ProfileUName ;
	public TextView ProfileUName;
	
	public Button BTN_Start, TemperatureHistoryYear, TemperatureHistoryMonth,
			TemperatureHistoryWeek;
	
	public ImageView ProfileUImage, AlarmBellForTemperaturePicker,
			statues_pain, statues_period, statues_sex, statues_fever,
			statues_medicine, statues_doctor;
	
	public SurfaceView TemperatureStatistic;
	
	public TemperatureHistoryStatue THS ;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		/*
		 * Initialization (components, variables ...)
		 */

		// Set Application's Title
		setTitle("Basal Body Temperature v_0.0.6");
		
		// Init TemperatureHistoryStatue
		THS = new TemperatureHistoryStatue(BasalBodyTemperature.this);

		// Create UI Component

		// --- TabWidget
		TabHost tabs = (TabHost) findViewById(R.id.BBTTabHost);

		// --- Tab_BBT
		// SenserItems = (Spinner) findViewById(R.id.SenserItems);
		// SysMessage = (TextView) findViewById(R.id.SysMessage);
		BTN_Start = (Button) findViewById(R.id.BTN_Start);
		TemperatureHistoryYear = (Button)findViewById(R.id.TemperatureHistoryYear);
		TemperatureHistoryMonth = (Button)findViewById(R.id.TemperatureHistoryMonth);
		TemperatureHistoryWeek = (Button)findViewById(R.id.TemperatureHistoryWeek);
		AlarmBellForTemperaturePicker = (ImageView)findViewById(R.id.AlarmBellForTemperaturePicker);
		statues_pain = (ImageView)findViewById(R.id.statues_pain);
		statues_period = (ImageView)findViewById(R.id.statues_period);
		statues_sex = (ImageView)findViewById(R.id.statues_sex);
		statues_fever = (ImageView)findViewById(R.id.statues_fever);
		statues_medicine = (ImageView)findViewById(R.id.statues_medicine);
		statues_doctor	 = (ImageView)findViewById(R.id.statues_doctor);
		// Init Alpha
		statues_pain.setAlpha(185);
		statues_period.setAlpha(75);
		statues_sex.setAlpha(75);
		statues_fever.setAlpha(75);
		statues_medicine.setAlpha(75);
		statues_doctor.setAlpha(75);
		
		// --- Tab_Profile
		ProfileUImage = (ImageView) findViewById(R.id.ProfileUImage);
		ProfileUName = (TextView) findViewById(R.id.ProfileUName);
		TemperatureStatistic = (SurfaceView) findViewById(R.id.TemperatureStatistic);

		// Generate TabWidget
		tabs.setup();

		TabHost.TabSpec BBTProfileTab = tabs.newTabSpec("BBTProfileTab");
		BBTProfileTab.setContent(R.id.BBTProfileTab);
		BBTProfileTab.setIndicator("Profile");
		tabs.addTab(BBTProfileTab);

		TabHost.TabSpec BBTMainTab = tabs.newTabSpec("BBTMainTab");
		BBTMainTab.setContent(R.id.BBTMainTab);
		BBTMainTab.setIndicator("BBT");
		tabs.addTab(BBTMainTab);

		TabHost.TabSpec BBTSystemTab = tabs.newTabSpec("BBTSystemTab");
		BBTSystemTab.setContent(R.id.BBTSystemTab);
		BBTSystemTab.setIndicator("System");
		tabs.addTab(BBTSystemTab);

		tabs.setCurrentTab(0);

		// Init: Tab_BBT

		// --- SenserItems: put items from
		// <Proj-root>/res/values/NameOfSeneors.xml to SenserItems
		// ArrayAdapter<CharSequence> NameOfSensers =
		// ArrayAdapter.createFromResource(this,
		// R.array.NameOfSensers,android.R.layout.simple_spinner_item);
		// NameOfSensers.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// SenserItems.setAdapter(NameOfSensers);

		// Init: Tab_Profile

		// --- ImageView
		ProfileUImage.setImageResource(R.drawable.def_profile_www);

		/*
		 * Create listeners for components (Button, Spinner...)
		 */

		// Listeners for tabs
		tabs_Listener tabs_L = new tabs_Listener(BasalBodyTemperature.this,
				TemperatureStatistic);
		tabs.setOnTabChangedListener(tabs_L);

		// Listeners for Tab_BBT
		// SenserItems_Listener SenserItems_L = new
		// SenserItems_Listener(BasalBodyTemperature.this);
		// SenserItems.setOnItemSelectedListener(SenserItems_L);
		BTN_Start_Listener BTN_Start_L = new BTN_Start_Listener(
				BasalBodyTemperature.this, TemperatureStatistic);
		BTN_Start.setOnClickListener(BTN_Start_L);

		// Listeners for Tab_Profile
		ProfileUName_Listener ProfileUName_L = new ProfileUName_Listener(
				BasalBodyTemperature.this);
		ProfileUName.setOnClickListener(ProfileUName_L);

		/*
		 * 
		 * DBhelper dbh = new DBhelper(BasalBodyTemperature.this);
		 * SQLiteDatabase wrdb = dbh.getWritableDatabase();
		 * 
		 * //Insert ContentValues args = new ContentValues();
		 * args.put("Temperature",36.11); long rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",36.33); rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",36.33); rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",36.11); rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",36.22); rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",36.33); rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",37.2); rowid =
		 * wrdb.insert("BBTData",null,args);
		 * 
		 * args.put("Temperature",37.1); rowid =
		 * wrdb.insert("BBTData",null,args); wrdb.close();
		 */

	}
}